package Pattern;

import java.util.Vector;

import Basics.Atom;
import Basics.Constant;
import Basics.DB;
import Basics.Program;
import Basics.Rule;
import Basics.Var;
import Derivation.SemiNaive;
import Parsing.ParseDB;

public class DebugPattern 
{
	public static void main (String [] args)
	{
		DB.getInstance().CreateDB();
		DB.getInstance().DropTableIfExists("imports");
		DB.getInstance().DropTableIfExists("exports");
		DB.getInstance().DropTableIfExists("dealsWith");
		
		ParseDB rfDB = new ParseDB ("yago2core_facts.clean.notypes.tsv", 100);//C:\\Users\\amirgilad\\Downloads\\
		Var a = new Var("a", "Country");
		Var b = new Var("b", "Country");
		Var c = new Var("c", "Product");
		Var f = new Var("f", "Country");
		
		Atom dealsWith1_1 = new Atom("dealWith", a,b);
		Atom dealsWith1_2 = new Atom("dealWith", a,b);
		Atom dealsWith1_3 = new Atom("dealWith", a,b);
		Atom dealsWith2 = new Atom("dealWith", a,f);
		Atom dealsWith3 = new Atom("dealWith", f,b);
		Atom dealsWith4 = new Atom("dealWith", b,a);
		Atom exported = new Atom("export", b,c);
		Atom imported = new Atom("import", a,c);
		
		Rule r1 = new Rule (dealsWith1_1, 1, imported, exported);
		Rule r2 = new Rule (dealsWith1_2, 1, dealsWith2, dealsWith3);
		Rule r3 = new Rule (dealsWith1_3, 1, dealsWith4);
		
		Program prog = new Program(r1, r2, r3);
		
		Constant Cuba = new Constant("Cuba", "Country");
		Constant France = new Constant("France", "Country");
		Constant cigars = new Constant("cigars", "Product");

		Constant Mexico = new Constant("Mexico", "Country");

		Constant wine = new Constant("wine", "Product");
		Constant weapon = new Constant("weapon", "Product");
		Constant Israel = new Constant("Israel", "Country");
		Constant Palestine = new Constant("Palestine", "Country");
		
		//Constant Albania = new Constant("Albania", "Country");
		//Constant Benin = new Constant("Benin", "Country");
		/*Atom exFw = new Atom ("exports",true, true, France, wine);
		Atom exCc = new Atom ("exports",true, true, Cuba, cigars);
		Vector<Atom> v1 = new Vector<Atom>(); 
		v1.add(exFw);
		v1.add(exCc);
		
		Atom imCw = new Atom ("imports",  true, true, Cuba, wine);
		Atom imMw = new Atom ("imports",  true, true, Mexico, wine);
		Atom imMc = new Atom ("imports",  true, true, Mexico, cigars);
		Atom imFc = new Atom ("imports", true, true, France, cigars);
		Vector<Atom> v2 = new Vector<Atom>(); 
		v2.add(imCw);
		v2.add(imMw);
		v2.add(imMc);
		v2.add(imFc);
		
		Map<String, Vector<Atom>> d = new HashMap<String, Vector<Atom>>();
		d.put("exports", v1);
		d.put("imports", v2);*/
		
		PatternNode root = new PatternNode ("dealWith",false, Palestine, Israel);
		//PatternNode root = new PatternNode ("dealsWith",false, Cuba, France);
		//PatternNode child1 = new PatternNode ("dealsWith",false, France, Cuba);
		//PatternNode grandchild1 = new PatternNode ("exports", false, Cuba, cigars);
		//PatternNode grandchild2 = new PatternNode ("exports",false, Cuba, cigars);
	
		//root.setChildren(child1);
		//child1.setParent(root); 
		//child1.setChildren(grandchild1);
		//grandchild1.setParent(child1);
		//child1.setChildren(grandchild);
		
		Vector<PatternNode> rootVec = new Vector<PatternNode> ();
		rootVec.add(root);
		
		//Vector<PatternNode> childVec = new Vector<PatternNode> ();
		//childVec.add(child1);
		//childVec.add(child2);
		
		//Vector<PatternNode> grandChildVec = new Vector<PatternNode> ();
		//grandChildVec.add(grandchild1);
		
		Vector<Vector<PatternNode>> pattern = new Vector<Vector<PatternNode>> ();
		pattern.add(rootVec); 
		//pattern.add(childVec); 
		//pattern.add(grandChildVec);
		DB.getInstance().DropTableIfExists("import");
		DB.getInstance().DropTableIfExists("export");
		DB.getInstance().DropTableIfExists("dealWith");

		Atom imPw = new Atom ("import", true, true, Palestine, weapon);
		Atom exIw = new Atom ("export", true, true, Israel, weapon);
		Atom exFw = new Atom ("export", true, true, France, wine);
		Atom exCc = new Atom ("export", true, true, Cuba, cigars);
		Atom imCw = new Atom ("import", true, true, Cuba, wine);
		Atom imMw = new Atom ("import", true, true, Mexico, wine);
		Atom imMc = new Atom ("import", true, true, Mexico, cigars);
		Atom imFc = new Atom ("import", true, true, France, cigars);
		
		
		DB.getInstance().DropTableIfExists("import");
		DB.getInstance().DropTableIfExists("export");
		
		DB.getInstance().Update(imPw);
		DB.getInstance().Update(exIw);
		DB.getInstance().Update(exFw);
		DB.getInstance().Update(exCc);
		DB.getInstance().Update(imCw);
		DB.getInstance().Update(imMw);
		DB.getInstance().Update(imMc);
		DB.getInstance().Update(imFc);
		
		SemiNaive sn = new SemiNaive(r1, r2, r3);
		sn.Run(false, false);
		
		
		IntersectWithProgramOffline iwp = new IntersectWithProgramOffline (sn.getParser().getC(), pattern);
		
		//iwp.IntersectNoTransitives(100);
		System.out.println(iwp.getC().getCircuit());
		
	}
	
	
}
